<?php

$objXajax->registerFunction("frmpay_loadGrid");
$objXajax->registerFunction("frmpay_edit");
$objXajax->registerFunction("frmpay_save");
$objXajax->registerFunction("frmpay_init");
//$objXajax->registerFunction("frmpay_type");
    
function frmpay_loadGrid(){     

    global $lang,$path;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $lang ='vi';
    $arrGrid = frmpay_getGrid();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('../templates/'.$lang.'/'.$path.'/main_pay_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('frmpay_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('frmpay_tbl');");                              
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function  frmpay_save($params){
    global $objDbSelect;
    $objResponse = new xajaxResponse();
    $money = $params['money'] ;
    $date = $params['date'] ;
    $description  = addslashes($params['description']);
    $edit = $params['hdEdit'];
    $id= $params['hdId'];
    $hotel_id =  $_SESSION['current']['hotel_id'];
    $user_id =  $_SESSION['current']['user_id'];
    if($edit==1){
        $sql = "UPDATE tbl_pay SET money='$money',date_pay='$date',description='$description',date_update=now(),user_update='$user_id'
        WHERE id ='$id'";
    }else{
         $sql = "INSERT INTO tbl_pay(money,date_pay,description,hotel_id,date_created,user_created,date_update,user_update) 
                                value('$money','$date','$description','$hotel_id',now(),'$user_id',now(),'$user_id')";   
    }

    $objDbSelect->Execute($sql);
    $objResponse->addScript(' xajax_frmpay_loadGrid();');
    $objResponse->addScript('changeWaiting(1);');
    return $objResponse->getXML(); 
} 
  
function  frmpay_getGrid(){
    global $objDbSelect,$lang;
    $hotel_id = $_SESSION['current']['hotel_id'];
    $sqlSelect = " SELECT * FROM tbl_pay  WHERE hotel_id = '$hotel_id' and datediff(now(),date_created)<30 order by date_created desc";
   // echo $sqlSelect; die();
    return $objDbSelect->GetArray($sqlSelect);
}  

function  frmpay_edit($id){
    global $objDbSelect;
    $sql = "SELECT *,REPLACE(REPLACE(description, '\n\r', '<br/>'),'\n','<br>') as description1 FROM tbl_pay WHERE id = '$id'";
    $arr = $objDbSelect->GetArray($sql);
    $objResponse = new xajaxResponse();
    $date = $arr[0]['date_pay'];
    $money = $arr[0]['money'];
    $description = addslashes($arr[0]['description1']);
    $objResponse->addScript("$('#frmpay_date').val('$date');");
    $objResponse->addScript("$('#frmpay_money').val('$money');");
    $objResponse->addScript("$('#frmpay_description').val('$description');");
    $objResponse->addScript('changeWaiting(1);');
    return $objResponse->getXML();
} 

function  frmpay_init(){
   $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax      
   $todate = SYSTEM_DATE;     
   $objResponse->addScript("$('#frmpay_date').val('$todate')");     
   return $objResponse->getXML(); // dong luon luon co khi goi ham ajax    
}


# end region process data
?>
